package com.yyl.render.render

import com.yyl.render.RenderConfig.i


open class YYLRender {


    // 回收全部环境
    protected external fun nativeOnDestroy()

    protected external fun nativeOnSurfaceCreated()

    protected external fun nativeOnSurfaceChanged(width: Int, height: Int)

    protected external fun nativeOnSurfaceDrawFrame()
    protected external fun nativeOnSurfaceDestroy()

    // 设置主程序
    protected external fun nativeSetProgramType(type: Int)

    // 
    protected external fun nativeLoadShaderScript(type: Int, scriptString: String)
     external fun nativeUpdateFrame(
        format: Int,
        width: Int,
        height: Int,
        data: ByteArray
    )

    protected external fun nativeSetTransformMatrix(
        translateX: Float,
        translateY: Float,
        scaleX: Float,
        scaleY: Float,
        degree: Int,
        mirror: Int
    )

    protected external fun nativeLoadFilterData(
        index: Int,
        format: Int,
        width: Int,
        height: Int,
        bytes: ByteArray
    )

//    YV12/YU12 (YUV420 采样方式)
//    NV21/NV12 属于 YUV420SP
    //    YUV420SP 格式有 2 个平面，Y 分量存储于一个平面，UV 分量交错存储于另一个平面
    companion object {

        const val ShaderVertex = 1
        const val ShaderFragment = 2

        //
        const val ProgramTypeSimple = 1
        const val ProgramTypeVideo = 2


        const val IMAGE_FORMAT_RGBA = 0x01
        const val IMAGE_FORMAT_NV21 = 0x02  //
        const val IMAGE_FORMAT_NV12 = 0x03  //
        const val IMAGE_FORMAT_I420 = 0x04  //YUV420   YU12（也称 I420） 格式的存储方式
        const val IMAGE_FORMAT_YUYV = 0x05 //YUV422
        const val IMAGE_FORMAT_GARY = 0x06
        const val IMAGE_FORMAT_I444 = 0x07
        const val IMAGE_FORMAT_P010 = 0x08


        fun initLib(){
            System.loadLibrary("yylRender")
            i("YYLRender","load yylRender.so")
        }
    }
}
